﻿using System;
using System.Data;
using VoteMS.BLL;
using VoteMS.Model;

/*
 * @author：zhu95
 * 
 */
namespace VoteMS.UI
{
    public partial class AddProject : System.Web.UI.Page
    {
        private  readonly ProjectsBLL projectsBll = new ProjectsBLL();
        private readonly ProjectTypeBLL projectTypeBll = new ProjectTypeBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) //回发
            {
                DataTable dt = projectTypeBll.GetProjectType();
                ddlTypeID.DataValueField = "TypeID";
                ddlTypeID.DataTextField = "TypeName";
                ddlTypeID.DataSource = dt;
                ddlTypeID.DataBind();
            }
        }
        /// <summary>
        /// 保存项目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ProjectModel project = new ProjectModel();
            project.ProjectName= txtProjectName.Text.Trim();
            project.TypeID= int.Parse( ddlTypeID.SelectedValue.Trim());
            project.ProjectDepart= txtProjectDepart.Text.Trim();
            project.ProjectImage= fileProjectImage.FileName;
            string path = Server.MapPath("~/Content/Images/") + project.ProjectImage;
            fileProjectImage.SaveAs(path);
            //string projectImage2 = fileProjectImage.PostedFile.FileName;
            project.ProjectInfo = txtProjectInfo.Text.Trim();
            project.ProjectNumber = 0;
            string message = projectsBll.AddProject(project);
            string[] result =  message.Split('|');
            Response.Write("<script>alert('" + result[0] + "')</script>");
        }
    }
}